#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

void menu1()
{
	printf("********************************************\n");
	printf("************** 0、exit      *****************\n");
	printf("************** 1、add      *****************\n");
	printf("************** 2、reduce   *****************\n");
	printf("************** 3、product  *****************\n");
	printf("************** 4、division *****************\n");
	printf("********************************************\n");
}

int add(int x, int y)
{
	return x + y;
}
int reduce(int x, int y)
{
	return x - y;
}
int  product(int x, int y)
{
	if (y == 0)
		printf("0 不能做除数!\n");
		
	else
		return x / y;
}
int division(int x, int y)
{
	return x * y;
}

void calc(int (*p)(int ,int))
{
	int x,  y;
	printf("Input two nums : ");
	scanf("%d %d", &x, &y);
	int ret = p(x, y);

	printf("result = %d\n", ret);
}
int main() 
{
	int input = 0;
	do 
	{
		menu1();
		printf(">");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			calc(add);
			break;
		case 2:
			calc(reduce);
			break;
		case 3:
			calc(product);
			break;
		case 4:
			calc(division);
			break;
		case 0:
			printf("退出程序。\n");
			break;
		default:
			printf("输入错误，请重新输入：");
			break;
		}
	} while (input);
}